package com.shu.thread;

import lombok.extern.slf4j.Slf4j;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2020/8/25 14:17
 */
@Slf4j
public class InteruptedTest {



    public static void main(String[] args) throws InterruptedException {

        Runnable runnable = () -> {
            int num = 0;
            try {
                while (!Thread.currentThread().isInterrupted() &&
                        num <= 1000) {
                    System.out.println(num);
                    num++;
                    Thread.sleep(1000000);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                log.info("1{}",Thread.currentThread().isInterrupted());
                e.printStackTrace();
            } finally {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.info("2{}",Thread.currentThread().isInterrupted());
            }
        };


        Thread thread = new Thread(runnable);
        thread.start();
        Thread.sleep(5);
        thread.interrupt();
        log.info("over!{}",Thread.currentThread().isInterrupted());
    }
}
